
var app = new Vue({
    el: '#myapp',
    data: {
        account: '',
        password: '',
        code: '',
        captcha: '/user/captcha.jpg',
        community: null,
        msg:''
    },
    created() {
        this.getCommunity();
        this.getAccount();
    },
    methods: {
        checkform(e) {
            e.preventDefault()
            var vm = this
            if (!vm.community) {
                vm.msg = "请选择小区";
                return
            }
            if (!vm.account || !vm.account.trim()) {
                vm.msg = "请输入手机号";
                return
            }
            if (!vm.password || !vm.password) {
                vm.msg = "请输入密码";
                return
            }

            if (!vm.code || !vm.code.trim()) {
                vm.msg = "请输入验证码";
                return
            }
            request.post("/user/login","communityId="+vm.community.deviceId+"&account="+vm.account.trim()+"&password="+vm.password.trim()+"&captcha="+vm.code.trim())
                    .then(body=>{
                        if(body.code === 204){
                            window.location.href="/userFaces.html"
                        }else{
                            vm.msg = body.msg
                        }
                    });
        },
        changeCaptcha() {
            this.captcha = '/user/captcha.jpg?time=' + (new Date().getTime())
        },
        getCommunity(){
            if(localStorage.currentCommunity){
                this.community = JSON.parse(localStorage.currentCommunity)
            }
        },
        getAccount(){
            if(localStorage.currentAccount){
                this.account = JSON.parse(localStorage.currentAccount);
            }
        },
        setAccount(){
            localStorage.currentAccount = JSON.stringify(this.account);
            console.log(localStorage.currentAccount);
        }   
    }
})